# 1. 进入到train下，
# 2. 进入到每个序列
import cv2 as cv
import os
seq = ['train','test']
n = 0
for s in seq:
    file_dir = 'datasets/gmot/'+s
    list1 = os.listdir(file_dir)
    for sen in os.listdir(file_dir):
        gt_file = os.path.join(file_dir, sen, 'gt', 'gt.txt')
        print(gt_file)
        f = open(gt_file,'r')
        gt_line = f.readlines()
        n += 1
        for i in gt_line:
            gt1 = i.split(',')
            img_name = '%06d'%(int(float(gt1[0])))
            img_dir = os.path.join(file_dir, sen, 'img1', img_name+'.jpg')
            print(img_dir)
            img = cv.imread(img_dir)
            if int(float(gt1[3])) < 0 or int(float(gt1[2])) < 0 or int(float(gt1[5])) < 0 or int(float(gt1[4])) < 0:
                continue
            else:
                img_crop = img[int(float(gt1[3])):int(float(gt1[3]))+int(float(gt1[5])), int(float(gt1[2])):int(float(gt1[2]))+int(float(gt1[4]))]
                cv.imwrite('datasets/gmot_test/%s/%04d_c1s%d_%06d_%02d.jpg'%(s, int(float(gt1[1])), n, int(float(gt1[0])), int(float(gt1[1]))), img_crop)
    